using System;
using System.Collections.Generic;
using System.Text;
using Castle.MonoRail.Framework;
using System.Web.Security;

namespace Stormwind.Controllers {
	/// <summary>
	/// Controller that manages authentication actions.
	/// </summary>
	public class AuthenticationController : SmartDispatcherController {
		#region Interface Contracts
		/// <summary>
		/// Authentication Data (Username and password) for the login view.
		/// </summary>
		public class AuthData {
			private string username;
			private string password;
			/// <summary>
			/// Username na tela de login.
			/// </summary>
			public string Username {
				get {
					return username;
				}
				set {
					username = value;
				}
			}
			/// <summary>
			/// Password da tela de login.
			/// </summary>
			public string Password {
				get {
					return password;
				}
				set {
					password = value;
				}
			}
		}
		#endregion Interface Contracts

		/// <summary>
		/// Shows the login form for the user.
		/// </summary>
		public void LoginForm() {

		}

		/// <summary>
		/// Performs login.
		/// </summary>
		public void DoLogin([DataBind("auth", From = ParamStore.Form)] AuthData authData) {
			Uri url = new Uri(Context.UrlReferrer);
			if (Request.IsLocal || url.Host.Contains("wowteam.net")) {
				FormsAuthentication.RedirectFromLoginPage(authData.Username, true);
			}
			CancelView();
		}
	}
}
